package com.shanwen.select.config;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.ViewControllerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurationSupport;

//import com.shanwen.select.interceptor.LoginInteceptor;

@Configuration
public class WebAppConfiguration extends WebMvcConfigurationSupport {

    @Value("${imagePath}")
    String imagePath;


    /**
     * 设置拦截器和添加不拦截的路径
     */
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(new LoginInterceptor()).addPathPatterns("/**").excludePathPatterns("/admin/login",
                "/static/**", "/file/**", "/wxapp/**", "/wxpay/**", "/chargeArticle/**","/*.txt");
    }


    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        // 需要配置 需要告知系统，这是要被当成静态文件的！
        // 第一个方法设置访问路径前缀，第二个方法设置资源路径
        registry.addResourceHandler("/**.txt").addResourceLocations("file:" + imagePath);
        registry.addResourceHandler("/static/**").addResourceLocations("classpath:/static/");
        registry.addResourceHandler("/file/**").addResourceLocations("file:" + imagePath);
    }

    @Override
    public void addViewControllers(ViewControllerRegistry registry) {
        // registry.addViewController("/error/404").setViewName("/admin/page_error/error_404.html");
        registry.addViewController("/index.html").setViewName("login");

    }


}